< previous page page_424 next page >

Page 424
If the data was not placed into the DataObject object when the OLEStartDrag event occurred, the source control's OLESetData event is triggered by the GetData method to retrieve the source control's data. The OLESetData event enables the source control to respond to only one request for a given format of data, as shown in the following code:
Private Sub picDisplay_OLESetData(Data As VB.DataObject, DataFormat As _ Integer)
   If DataFormat = vbCFText Then
      Data.SetData txtLastName.SelText, vbCfText
   End If
End Sub
Whenever the effect argument is changed in the OLEDragDrop event, the source control's OLECompleteDrag event is triggered. This enables the source control to finish the drag-and-drop process. This event is the last one to be triggered in any drag-and-drop operation.
The OLECompleteDrag Event
The OLECompleteDrag event has only the effect argument, which is used to inform the source control of the action that was taken when the data is dropped. If a move was specified and the data is dropped into the target, the following code deletes the data from the source control:
Private Sub txtLastName_OLECompleteDrag(Effect As Long)
   If Effect = vbDropEffectMove Then
      txtLastName.SelText = 
   End If
End Sub
The button and shift arguments in the OLEDragDrop event are used to respond to the state of the mouse buttons and the Shift, Ctrl, and Alt keys. For example, when dragging data into a control, you can enable the user to specify a copy operation by pressing the Ctrl key while dragging the data. In the following code, the shift argument is used to determine if the Ctrl key is pressed when the data is dropped. If it is, a copy is performed, otherwise, a move is performed:
Private Sub picDisplay_OLEDragDrop(Data As VB.DataObject, Effect As Long,_
Button As _
         Integer, Shift As Integer, X As Single, Y As Single)
    If Shift And vbCtrlMask Then
        picDisplay.Text = Data.GetData(vbCFText)
        Effect = vbDropEffectCopy
    Else
        picDisplay.Text = Data.GetData(vbCFText)
        Effect = vbDropEffectMove
    End If
End Sub

 
< previous page page_424 next page >

If you like this book, buy it!